<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('page');
	$zhaoshangid=pdo_getcolumn('jy_mzhaoshang_list',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'id');
	$return['orderfee']=pdo_getsum('jy_mzhaoshang_order',array('uniacid'=>$_SESSION['uniacid'],'zhaoshangid'=>$zhaoshangid),'order_price');
	$return['ordernum']=pdo_count('jy_mzhaoshang_order',array('uniacid'=>$_SESSION['uniacid'],'zhaoshangid'=>$zhaoshangid));
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$lastdaytime = $daytime-24*3600;
	$return['totalday']=$this->sum('order',array('uniacid'=>$_SESSION['uniacid'],'zhaoshangid'=>$zhaoshangid,'createtime >'=>$daytime),'order_price');
	$return['totallastday']=$this->sum('order',array('uniacid'=>$_SESSION['uniacid'],'zhaoshangid'=>$zhaoshangid,'createtime between'=>array($lastdaytime,$daytime)),'order_price');
	$return['commission_total']=$this->sum('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'money');
	$return['list']=array();
	$return['params']=array(
		'level'=>0,
		'page'=>1,
	);
	$return['psize']=20;
	set_html('title',$return['setting']['torder']?:'分销订单');
	exi($return);
}
if($_RQ['op']=='list'){
	$zhaoshangid=pdo_getcolumn('jy_mzhaoshang_list',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'id');
	$params=array('uniacid'=>$_SESSION['uniacid'],'zhaoshangid'=>$zhaoshangid);
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
	);
	$list=$this->get_list('commission',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['member']=model('core/member')->basic($item['mid']);
		$order=pdo_get('jy_weishop_order',array('id'=>$item['orderid']),array('mid','merchid','ordersn'));
		$item['merchname']=pdo_getcolumn('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['merchid']),'merchname');
		$item['ordersn']=$order['ordersn'];	
		$item['createtime']=date('Y-m-d H:i',$item['createtime']);	
	}
	//exi('num'.count($list),'error');
	exi($list);
}
?>